#include "dialog.h"
#include "ui_dialog.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include "timeserver.h"
Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);

    setWindowTitle(tr("多线程时间服务器"));
    label1 = new QLabel(tr("服务器端口:"));
    label2 = new QLabel;

    quitBtn = new QPushButton(tr("退出"));
    QHBoxLayout* BtnLayout = new QHBoxLayout;
    BtnLayout->addStretch(1);
    BtnLayout->addWidget(quitBtn);
    BtnLayout->addStretch(1);

    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    mainLayout->addWidget(label1);
    mainLayout->addWidget(label2);
    mainLayout->addLayout(BtnLayout);
    connect(quitBtn,SIGNAL(clicked()),this,SLOT(close()));


    //网络实现部分
    count = 0;
    timeServer = new TimeServer(this);//Tcp服务器中，用TcpServer指定父指针，而客户端中，用TcpSocket指定父指针
    if(!timeServer->listen())
    {
        QMessageBox::critical(this,tr("多线程时间服务器"),tr("无法启动服务器:%1.").arg(timeServer->errorString()));
        close();
        return;
    }
    label1->setText(tr("服务q端口：%1.").arg(timeServer->serverPort()));
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::slotShow()
{
    label2->setText(tr("第%1次请求完毕").arg(++count));
}

